<!--
* @author luguoxiang
* @date 2021-09-07
* 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <t-col v-if="vif" v-show="show" v-bind="colProps">
    <t-form-item v-bind="formItemProps" :rules="rules">
      <template v-for="(x, key) in $slots" #[key]="scope">
        <slot :name="key" v-bind="scope" :component-props="componentProps"></slot>
      </template>
    </t-form-item>
  </t-col>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const props = defineProps({
  initialized: {
    type: Function,
  },
});

const vif = ref(true);
const show = ref(true);
const colProps = ref({});
const formItemProps = ref({});
const rules = ref();
const componentProps = ref({});

props.initialized({
  updateIf: (state: boolean) => {
    vif.value = state;
  },
  updateHidden: (state: boolean) => {
    show.value = !state;
  },
  updateCol: (state: any) => {
    colProps.value = state;
  },
  updateFormItem: (state: any) => {
    formItemProps.value = state;
  },
  updateRules: (state: any) => {
    rules.value = state;
  },
  updateProps: (state: any, merge?: boolean) => {
    if (merge) {
      for (const key in state) {
        componentProps.value[key] = state[key];
      }
    } else {
      componentProps.value = state;
    }
  },
  updateProp: (key: string, val: any) => {
    componentProps.value[key] = val;
  },
});
</script>
